package com.yanq.liancar.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.yanq.liancar.R;
import com.yanq.liancar.adapter.LuckDrawListAdapter;
import com.yanq.liancar.base.BaseLYFragment;
import com.yanq.liancar.bean.LuckDrawListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.Unbinder;

public class LuckDrawFragment extends BaseLYFragment {

    @BindView(R.id.order_recyclerview)
    RecyclerView orderRecyclerview;
    @BindView(R.id.smartrefreshlayout)
    SmartRefreshLayout smartrefreshlayout;

    private int page = 1;
    private boolean isClear;
    private int auditStatus;
    private LuckDrawListAdapter adapter;
    private List<LuckDrawListBean.DataBean.ListBean> luckDrawListBeanList=new ArrayList<>();

    public static LuckDrawFragment newInstance(int auditStatus) {
        Bundle bundle = new Bundle();
        bundle.putInt("auditStatus", auditStatus);
        LuckDrawFragment pageFragment = new LuckDrawFragment();
        pageFragment.setArguments(bundle);
        return pageFragment;
    }

    @Override
    protected void onCreateViewLazy(Bundle savedInstanceState) {
        super.onCreateViewLazy(savedInstanceState);
        setContentView(R.layout.fragment_orderlist);
        auditStatus = getArguments().getInt("auditStatus");
        initRecyclerview();
        initListener();

        setData();
    }

    private void setData() {
//        LuckDrawListBean bean1=new LuckDrawListBean();
//        bean1.setTitle("中奖啦！恭喜获得洗车代金劵100-10一张");
//        bean1.setTime("2018-08-12 16:12");
//        luckDrawListBeanList.add(bean1);
//        LuckDrawListBean bean2=new LuckDrawListBean();
//        bean2.setTitle("中奖啦！恭喜获得洗车代金劵100-50一张");
//        bean2.setTime("2018-08-12 16:12");
//        luckDrawListBeanList.add(bean2);

    }


    private void initRecyclerview() {

        orderRecyclerview.setNestedScrollingEnabled(false);
        orderRecyclerview.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new LuckDrawListAdapter(R.layout.item_luckdraw, luckDrawListBeanList);
        orderRecyclerview.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });
    }

    private void initListener() {
        smartrefreshlayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                page = 1;
                isClear = true;


                refreshlayout.finishRefresh();
            }
        });
        smartrefreshlayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                page++;
                isClear = false;

                refreshLayout.finishLoadMore();
            }

        });
    }

}
